package stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamCollect {
    public static void main(String[] args) {
        Stream<Integer> stream = Stream.of(12, 22, 32, 42, 52);
//        List<Integer> list = stream.collect(Collectors.toList());
//        for (Integer num : list) {
//            System.out.println("num = " + num);
//        }

//        Set<Integer> set = stream.collect(Collectors.toSet());
//        for (Integer integer : set) {
//            System.out.println("integer = " + integer);
//        }
        //流中的内容放到ArrayList中
        ArrayList<Integer> list = stream.collect(Collectors.toCollection(ArrayList::new));
        for (Integer integer : list) {
            System.out.println("integer = " + integer);
        }
    }
}
